/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package linkedlistsample;

/**
 *
 * @author parallels
 */
public class SimpleList {
    
    private Node head;
    
    public SimpleList () {
        head = new Node(null);
    }
    
    public void insert (Node n) {
        // insertar al ppio
        n.setNext(head.getNext());
        head.setNext(n);
    }
    
    public Node getFirst() {
        return head.getNext();
    }
    
    public Node getNext (Node n) {
        return (n.getNext());
    }
    
    public void delete (Node n) {
        Node current = head;
        Node next = current.getNext();
        while (next != null) {
            //System.out.println (current.getObject());
            //System.out.println(next.getObject() + "-" + n.getObject());
            
            // == esta facilmente definido para enteros/strings simples, etc
            // pero que pasa si se insertan objetos no simples ??
            // solucion : redefinir el metodo equals ??
            if (next.getObject() == n.getObject()) { // == 
                current.setNext(next.getNext());
                // no avanzar el current x si hay q eliminar el sigte nodo
            } else {
                current = next;
            }
            next = current.getNext();
        }
    }
    
}
